package com.kate.mall.member.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.member.dao.MemberDao;
import com.kate.mall.member.entity.MemberEntity;
import com.kate.mall.member.service.MemberService;
import com.kate.mall.member.vo.UserForm;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import com.kate.mall.common.utils.Query;

@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {

    @Resource
    private MemberDao memberDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                generatorQueryWrapper(params)
        );

        return new PageUtils(page);
    }
    public QueryWrapper generatorQueryWrapper(Map<String, Object> params) {//is_hot=1
        QueryWrapper<MemberEntity> queryWrapper = new QueryWrapper<>();
        if (params.containsKey("username")) {
            //where is_hot=1
            queryWrapper.eq("username", params.get("username"));
        }
        queryWrapper.eq("deleted",0);
        return queryWrapper;
    }


    public boolean save(UserForm userForm) {

        MemberEntity memberEntity =new MemberEntity();
        BeanUtil.copyProperties(userForm,memberEntity);

        return memberDao.insert(memberEntity)>1?true:false;
    }

}